package com.dvd.cjc.gcjc001;
import org.hibernate.Transaction;

import com.dvd.dao.usr.*;
public class GCJC001Model {
	public TUsr searchById(String id)
	{
		TUsrDAO dao  = new TUsrDAO();
		TUsr usr = null;
		Transaction tran = dao.getSession().beginTransaction();
		
		usr=dao.findById(id);
		
		tran.commit();
		dao.getSession().close();
		return usr;
	}
	
	public boolean entryAdmin(String flag,TUsr usr)
	{
		TUsrDAO dao = new TUsrDAO();
		Transaction tran = dao.getSession().beginTransaction();
		if(flag.equals("new"))
		{
			dao.getSession().save(usr);
		}
		else
		{
			TUsr tempusr =(TUsr)dao.getSession().createCriteria(TUsr.class).list().get(0);
			dao.delete(tempusr);
			dao.save(usr);
		}
		tran.commit();
		dao.getSession().close();
		return true;
	}

}
